<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"
	xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
	<xsl:output method="xml" indent="yes" encoding="UTF-8"/>



	<xsl:template match="/">
		<dsc>
			<xsl:apply-templates select="//row"/>
		</dsc>
	</xsl:template>

	<xsl:template match="row">
		<c level="item" id="{normalize-space(elem[@mapping='id'])}">
			<did>
				<unittitle>
					<xsl:value-of select="elem[@mapping='unittitle']"/>
				</unittitle>
				<xsl:if test="string(normalize-space(elem[@mapping='unitid']))">
					<unitid type="{string(normalize-space(elem[@mapping='unitid-type']))}">
						<xsl:value-of select="normalize-space(elem[@mapping='unitid'])"/>
					</unitid>
				</xsl:if>
				<xsl:if test="string(normalize-space(elem[@mapping='unitdate']))">
					<unitdate normal="{normalize-space(elem[@mapping='unitdate-normal'])}">
						<xsl:value-of select="normalize-space(elem[@mapping='unitdate'])"/>
					</unitdate>
				</xsl:if>
				<xsl:for-each select="elem[@mapping='container']">
					<xsl:if test="string(normalize-space(.))">
						<container type="">
							<xsl:value-of select="normalize-space(.)"/>
						</container>
					</xsl:if>
				</xsl:for-each>
				<xsl:for-each select="elem[@mapping='department']">
					<xsl:if test="string(normalize-space(.))">
						<materialspec type="department">
							<xsl:value-of select="normalize-space(.)"/>
						</materialspec>
					</xsl:if>
				</xsl:for-each>
				<xsl:for-each select="elem[@mapping='script']">
					<xsl:if test="string(normalize-space(.))">
						<materialspec type="script">
							<xsl:value-of select="normalize-space(.)"/>
						</materialspec>
					</xsl:if>
				</xsl:for-each>
				<xsl:if
					test="string(normalize-space(elem[@mapping='city'])) or string(normalize-space(elem[@mapping='region'])) or string(normalize-space(elem[@mapping='state'])) or string(normalize-space(elem[@mapping='place']))">
					<origination>
						<xsl:for-each select="elem[@mapping='city']">
							<xsl:if test="string(normalize-space(.))">
								<geogname role="city">
									<xsl:value-of select="normalize-space(.)"/>
								</geogname>
							</xsl:if>
						</xsl:for-each>
						<xsl:for-each select="elem[@mapping='region']">
							<xsl:if test="string(normalize-space(.))">
								<geogname role="region">
									<xsl:value-of select="normalize-space(.)"/>
								</geogname>
							</xsl:if>
						</xsl:for-each>
						<xsl:for-each select="elem[@mapping='state']">
							<xsl:if test="string(normalize-space(.))">
								<geogname role="state">
									<xsl:value-of select="normalize-space(.)"/>
								</geogname>
							</xsl:if>
						</xsl:for-each>
						<xsl:for-each select="elem[@mapping='place']">
							<xsl:if test="string(normalize-space(.))">
								<geogname>
									<xsl:value-of select="normalize-space(.)"/>
								</geogname>
							</xsl:if>
						</xsl:for-each>
					</origination>
				</xsl:if>
				<physdesc>
					<genreform type="format">
						<xsl:value-of select="elem[@name='format']"/>
					</genreform>
					<xsl:for-each select="elem[@mapping='denomination']">
						<xsl:if test="string(normalize-space(.))">
							<genreform type="denomination">
								<xsl:value-of select="normalize-space(.)"/>
							</genreform>
						</xsl:if>
					</xsl:for-each>
					<xsl:if test="string(normalize-space(elem[@mapping='dimensions']))">
						<dimensions>
							<xsl:value-of select="normalize-space(elem[@mapping='dimensions'])"/>
						</dimensions>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='axis']))">
						<physfacet type="axis">
							<xsl:value-of select="normalize-space(elem[@mapping='axis'])"/>
						</physfacet>
					</xsl:if>
					<xsl:for-each select="elem[@mapping='color']">
						<xsl:if test="string(normalize-space(.))">
							<physfacet type="color">
								<xsl:value-of select="normalize-space(.)"/>
							</physfacet>
						</xsl:if>
					</xsl:for-each>
					<xsl:if test="string(normalize-space(elem[@mapping='counterstamp']))">
						<physfacet type="counterstamp">
							<xsl:value-of select="normalize-space(elem[@mapping='counterstamp'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='dob']))">
						<physfacet type="dob">
							<xsl:value-of select="normalize-space(elem[@mapping='dob'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='edge']))">
						<physfacet type="edge">
							<xsl:value-of select="normalize-space(elem[@mapping='edge'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='manufacture']))">
						<physfacet type="manufacture">
							<xsl:value-of select="normalize-space(elem[@mapping='manufacture'])"/>
						</physfacet>
					</xsl:if>
					<xsl:for-each select="elem[@mapping='material']">
						<xsl:if test="string(normalize-space(.))">
							<physfacet type="material">
								<xsl:value-of select="normalize-space(.)"/>
							</physfacet>
						</xsl:if>
					</xsl:for-each>
					<xsl:if test="string(normalize-space(elem[@mapping='netGrade']))">
						<physfacet type="netGrade">
							<xsl:value-of select="normalize-space(elem[@mapping='netGrade'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='obverseGrade']))">
						<physfacet type="obverseGrade">
							<xsl:value-of select="normalize-space(elem[@mapping='obverseGrade'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='obverse_iconography']))">
						<physfacet type="obverse_iconography">
							<xsl:value-of
								select="normalize-space(elem[@mapping='obverse_iconography'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='obverse_legend']))">
						<physfacet type="obverse_legend">
							<xsl:value-of select="normalize-space(elem[@mapping='obverse_legend'])"
							/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='obverseSymbol']))">
						<physfacet type="obverseSymbol">
							<xsl:value-of select="normalize-space(elem[@mapping='obverseSymbol'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='reverseGrade']))">
						<physfacet type="reverseGrade">
							<xsl:value-of select="normalize-space(elem[@mapping='reverseGrade'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='reverse_iconography']))">
						<physfacet type="reverse_iconography">
							<xsl:value-of
								select="normalize-space(elem[@mapping='reverse_iconography'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='reverse_legend']))">
						<physfacet type="reverse_legend">
							<xsl:value-of select="normalize-space(elem[@mapping='reverse_legend'])"
							/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='reverseSymbol']))">
						<physfacet type="reverseSymbol">
							<xsl:value-of select="normalize-space(elem[@mapping='reverseSymbol'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='sernum']))">
						<physfacet type="sernum">
							<xsl:value-of select="normalize-space(elem[@mapping='sernum'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='signature']))">
						<physfacet type="signature">
							<xsl:value-of select="normalize-space(elem[@mapping='signature'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='shape']))">
						<physfacet type="shape">
							<xsl:value-of select="normalize-space(elem[@mapping='shape'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='symbol']))">
						<physfacet type="symbol">
							<xsl:value-of select="normalize-space(elem[@mapping='symbol'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='undertype']))">
						<physfacet type="undertype">
							<xsl:value-of select="normalize-space(elem[@mapping='undertype'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='watermark']))">
						<physfacet type="watermark">
							<xsl:value-of select="normalize-space(elem[@mapping='watermark'])"/>
						</physfacet>
					</xsl:if>
					<xsl:if test="string(normalize-space(elem[@mapping='weight']))">
						<physfacet type="weight">
							<xsl:value-of select="normalize-space(elem[@mapping='weight'])"/>
						</physfacet>
					</xsl:if>
				</physdesc>
				<xsl:if
					test="string(normalize-space(elem[@mapping='obverse_thumb'])) or string(normalize-space(elem[@mapping='obverse_screen'])) or string(normalize-space(elem[@mapping='obverse_large'])) or string(normalize-space(elem[@mapping='reverse_thumb'])) or string(normalize-space(elem[@mapping='reverse_screen'])) or string(normalize-space(elem[@mapping='reverse_large']))">
					<daogrp>
						<xsl:if test="string(normalize-space(elem[@mapping='obverse_thumb']))">
							<daoloc label="thumb_obv"
								href="{normalize-space(elem[@mapping='obverse_thumb'])}"/>
						</xsl:if>
						<xsl:if test="string(normalize-space(elem[@mapping='obverse_screen']))">
							<daoloc label="screen_obv"
								href="{normalize-space(elem[@mapping='obverse_screen'])}"/>
						</xsl:if>
						<xsl:if test="string(normalize-space(elem[@mapping='obverse_large']))">
							<daoloc label="master_obv"
								href="{normalize-space(elem[@mapping='obverse_large'])}"/>
						</xsl:if>
						<xsl:if test="string(normalize-space(elem[@mapping='reverse_thumb']))">
							<daoloc label="thumb_rev"
								href="{normalize-space(elem[@mapping='reverse_thumb'])}"/>
						</xsl:if>
						<xsl:if test="string(normalize-space(elem[@mapping='reverse_screen']))">
							<daoloc label="screen_rev"
								href="{normalize-space(elem[@mapping='reverse_screen'])}"/>
						</xsl:if>
						<xsl:if test="string(normalize-space(elem[@mapping='reverse_large']))">
							<daoloc label="master_rev"
								href="{normalize-space(elem[@mapping='reverse_large'])}"/>
						</xsl:if>
					</daogrp>
				</xsl:if>
			</did>
			<xsl:if test="string(normalize-space(elem[@mapping='acqinfo']))">
				<acqinfo>
					<p>
						<xsl:value-of select="normalize-space(elem[@mapping='acqinfo'])"/>
					</p>
				</acqinfo>
			</xsl:if>
			<xsl:if test="string(normalize-space(elem[@mapping='appraisal']))">
				<appraisal>
					<p>
						<xsl:value-of select="normalize-space(elem[@mapping='appraisal'])"/>
					</p>
				</appraisal>
			</xsl:if>
			<xsl:if
				test="string(normalize-space(elem[@mapping='ref'])) or string(normalize-space(elem[@mapping='bibref-title'])) or string(normalize-space(elem[@mapping='bibref-num']))">
				<bibliography>
					<xsl:for-each select="elem[@mapping='ref']">
						<xsl:if test="string(normalize-space(.))">
							<ref show="new" actuate="onrequest" href="{normalize-space(.)}"/>
						</xsl:if>
					</xsl:for-each>
					<xsl:if
						test="string(normalize-space(elem[@mapping='bibref-title'])) or string(normalize-space(elem[@mapping='bibref-num']))">
						<bibref>
							<title render="italic">
								<xsl:value-of
									select="normalize-space(elem[@mapping='bibref-title'])"/>
							</title>
							<num type="idno">
								<xsl:value-of select="normalize-space(elem[@mapping='bibref-num'])"
								/>
							</num>
						</bibref>
					</xsl:if>
				</bibliography>
			</xsl:if>
			<xsl:if
				test="string(normalize-space(elem[@mapping='city'])) or string(normalize-space(elem[@mapping='state'])) or string(normalize-space(elem[@mapping='region'])) or string(normalize-space(elem[@mapping='place'])) or string(normalize-space(elem[@mapping='corpname'])) or string(normalize-space(elem[@mapping='famname'])) or string(normalize-space(elem[@mapping='persname'])) or string(normalize-space(elem[@mapping='deity'])) or string(normalize-space(elem[@mapping='subject']))">
				<controlaccess>
					<xsl:for-each select="elem[@mapping='city']">
						<xsl:if test="string(normalize-space(.))">
							<geogname role="city" normal="">
								<xsl:value-of select="."/>
							</geogname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='region']">
						<xsl:if test="string(normalize-space(.))">
							<geogname role="region" normal="">
								<xsl:value-of select="."/>
							</geogname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='state']">
						<xsl:if test="string(normalize-space(.))">
							<geogname role="state" normal="">
								<xsl:value-of select="."/>
							</geogname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='place']">
						<xsl:if test="string(normalize-space(.))">
							<geogname normal="">
								<xsl:value-of select="."/>
							</geogname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='issuer']">
						<xsl:if test="string(normalize-space(.))">
							<corpname role="issuer">
								<xsl:value-of select="."/>
							</corpname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='maker']">
						<xsl:if test="string(normalize-space(.))">
							<corpname role="maker">
								<xsl:value-of select="."/>
							</corpname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='corpname']">
						<xsl:if test="string(normalize-space(.))">
							<corpname role="">
								<xsl:value-of select="."/>
							</corpname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='famname']">
						<xsl:if test="string(normalize-space(.))">
							<famname role="">
								<xsl:value-of select="."/>
							</famname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='artist']">
						<xsl:if test="string(normalize-space(.))">
							<persname role="artist" normal="">
								<xsl:value-of select="."/>
							</persname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='engraver']">
						<xsl:if test="string(normalize-space(.))">
							<persname role="engraver" normal="">
								<xsl:value-of select="."/>
							</persname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='persname']">
						<xsl:if test="string(normalize-space(.))">
							<persname role="" normal="">
								<xsl:value-of select="."/>
							</persname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='deity']">
						<xsl:if test="string(normalize-space(.))">
							<persname role="deity" normal="">
								<xsl:value-of select="."/>
							</persname>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='subject']">
						<xsl:if test="string(normalize-space(.))">
							<subject>
								<xsl:value-of select="."/>
							</subject>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='subjectEvent']">
						<xsl:if test="string(normalize-space(.))">
							<subject type="subjectEvent">
								<xsl:value-of select="."/>
							</subject>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='subjectIssuer']">
						<xsl:if test="string(normalize-space(.))">
							<subject type="subjectIssuer">
								<xsl:value-of select="."/>
							</subject>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='subjectPerson']">
						<xsl:if test="string(normalize-space(.))">
							<subject type="subjectPerson">
								<xsl:value-of select="."/>
							</subject>
						</xsl:if>
					</xsl:for-each>
					<xsl:for-each select="elem[@mapping='subjectPlace']">
						<xsl:if test="string(normalize-space(.))">
							<subject type="subjectPlace">
								<xsl:value-of select="."/>
							</subject>
						</xsl:if>
					</xsl:for-each>
				</controlaccess>
			</xsl:if>
			<xsl:if test="string(normalize-space(elem[@mapping='custodhist']))">
				<custodhist>
					<p>
						<xsl:value-of select="normalize-space(elem[@mapping='custodhist'])"/>
					</p>
				</custodhist>
			</xsl:if>
			<!--<xsl:if test="string(normalize-space(elem[@mapping='phystech']))">
				<phystech>
					<p>
						<xsl:value-of select="normalize-space(elem[@mapping='phystech'])"/>
					</p>
				</phystech>
			</xsl:if>-->
		</c>
	</xsl:template>

</xsl:stylesheet>
